package com.spsoft.workflow.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spsoft.core.annotation.AnonymousAccess;
import com.spsoft.core.annotation.Log;
import com.spsoft.core.enums.LogActionType;
import com.spsoft.core.enums.LogMenuEnum;
import com.spsoft.core.model.Result;
import com.spsoft.core.utils.SecurityUtils;
import com.spsoft.workflow.model.dto.bus.*;
import com.spsoft.workflow.model.vo.biz.BusinessFlowVo;
import com.spsoft.workflow.service.ProcessBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 流程业务表;--主键序列 SEQ_WF_PROCESS_BUSINESS 前端控制器
 * </p>
 *
 * @author dlchen
 * @since 2023-11-13
 */
@Api(tags = {"业务流程（首页代办，部分流程我发起的）"})
@RestController
@RequestMapping("/wfProcessBusiness")
@RequiredArgsConstructor
@Validated
@Slf4j
public class WfProcessBusinessController {

    private final ProcessBusinessService processBusinessService;


    @ApiOperation("我发起的流程")
    @AnonymousAccess(value = "/queryStartProcessMyself", method = RequestMethod.POST, permissionCode = "VMS_PROCESS_MYSELF")
    @Log(value = "我发起的流程", type = LogActionType.SELECT, menuName = LogMenuEnum.WORKFLOW)
    public Result<IPage<BusinessFlowVo>> queryStartProcessMyself(@RequestBody QueryProcessDto q) {
        q.setUserCode(SecurityUtils.getUserCode());
        q.setDeptCode(SecurityUtils.getDeptCode());
        return processBusinessService.queryStartProcessMyself(q);
    }

    @ApiOperation("首页流程")
    @AnonymousAccess(value = "/homeProcess", method = RequestMethod.POST, permissionCode = "VMS_PROCESS_INDEX")
    @Log(value = "首页流程", type = LogActionType.SELECT, menuName = LogMenuEnum.WORKFLOW)
    public Result<IPage<BusinessFlowVo>> homeProcess(@RequestBody QueryProcessDto q) {
        q.setUserCode(SecurityUtils.getUserCode());
        q.setDeptCode(SecurityUtils.getDeptCode());
        if (q.getIsDone() == 0) {
            return processBusinessService.queryProcessToDo(q);
        } else {
            return processBusinessService.queryProcessHasDone(q);
        }
    }
    @ApiOperation("查询代办流程状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "busId", value = "流程ID", dataTypeClass = Long.class, dataType = "Long", paramType = "query", required = true)
    })
    @AnonymousAccess(value = "/queryProcess", method = RequestMethod.POST, permissionCode = "VMS_PROCESS_QUERY_PROCESS")
    @Log(value = "查询代办流程状态", type = LogActionType.SELECT, menuName = LogMenuEnum.WORKFLOW)
    public Result<BusinessFlowVo> queryProcess(@RequestParam(value = "busId") Long busId) {
       return processBusinessService.queryProcessToDoBuyId(busId,SecurityUtils.getUserCode(),SecurityUtils.getDeptCode());
    }

}

